package com.wgchao.authmanager.domain.model;

import com.wgchao.authmanager.infrastructure.exception.ObjectDisabledException;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;

/**
 * @ClassName: SetRoleWithAdminDomainService
 * @author: wgchao
 * @createTime: 2020/4/28 3:02 PM
 * @Description: 设置账户角色
 */
@Service
public class SetRoleWithAdminDomainService {

    /**
     * 设置账户角色
     */
    public UserRole setRolesToAdmin(Administrator administrator, List<Role> roles, String operator){
        if(!administrator.normal()){
            throw new ObjectDisabledException("账户不可用");
        }
        UserRole userRole = new UserRole(administrator.getUname(), new Operator(operator, new Date()));
        for(Role role : roles){
            userRole.addRole(role);
        }
        return userRole;
    }

}
